﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DataparseEngine;

public partial class law : System.Web.UI.Page
{
    private String targetURL = "http://www.unitalen.com.cn/servlet/Category?Node=";
    private String detailsURL = "http://www.unitalen.com.cn/";
    private DataProvider localProvider = new LocalDataProvider();
    private DataProvider remoteProvider = new RemoteDataProvider();
    private Hashtable table=new Hashtable();

    protected void Page_Load(object sender, EventArgs e)
    {
        table.Add("10169","patent");
        table.Add("10168", "brand");
        table.Add("10170", "copyright");
        table.Add("10395", "other");
        /*remoteProvider.setCharset("utf-8");
        Session["current"] = "patent";
        String str = remoteProvider.provide(targetURL + Request.QueryString["current"] + "&l4749=25", "<div.*(?=Content2)(.|\n)*?</div>");*/
        
        Session["current"] = table[Request.QueryString["current"]];
        PatentDataSource.DataFile = Server.MapPath("~") + "/laws/" + Session["current"] + ".xml";
        PatentDataSource.DataBind();
        lawBulletList.DataBind();
        
        /*UIUtil.createBulletList(this.lawBulletList, str, 100,-1);
        UIUtil.fetchDataToFile(Server.MapPath("~") + "/laws/", detailsURL, str);*/
    }

    protected void viewLawDetails(object sender, BulletedListEventArgs e)
    {
        Console.WriteLine("ddddddddddddddddddddddddddddddddddddd");
        Session["current"] = table[Request.QueryString["current"]];
        //char[] splitor=new char[]{'\''};
        String fileName=((BulletedList)sender).Items[e.Index].Value;//.Split(splitor)[0].Substring(1);
        /*String subUrl2 = subUrl.Split(splitor)[0].Substring(1);
        char[] splitor2 = new char[] { '/' };
        String fileName = subUrl2.Split(splitor2)[2];*/
        localProvider.setCharset("utf-8");
        this.innerContent.InnerHtml = localProvider.provide(Server.MapPath("~") + "/laws/" + Session["current"] + "/" + fileName, "<ul.*(?=xijie)(.|\n)*?</ul>");
        back.Visible = true;
    }

    protected void getLawListItems(object sender, BulletedListEventArgs e)
    {
        String value=((BulletedList) sender).Items[e.Index].Value;
        Session["current"] = (String)table[value];
        /*String str = remoteProvider.provide(targetURL + value, "<div.*(?=Content2)(.|\n)*?</div>");
        UIUtil.createBulletList(this.lawBulletList, str, 20, -1);
        Response.Redirect("law.aspx?current=" + value);*/
        if (this.FindControl("lawBulletList")==null)
        {
            PatentDataSource.DataFile = Server.MapPath("~") + "/laws/" + table[value] + ".xml";
            PatentDataSource.DataBind();
            lawBulletList.DataBind();
        }
    }
}
